#!/bin/bash

if [ 1 == $1 ]
then
	while [ 1 ]
	do
		daemon_name=$(ps -ef | grep pz_channel | grep -v grep)
		echo $daemon_name
		if ["$daemon_name" == ""]
		then
				cd ../pz_channel
				Debug/pz_channel &
		fi
	sleep 60
	done
fi


if [ 2 == $1 ]
then
	while [ 1 ]
	do
		daemon_name=$(ps -ef | grep CacheServer | grep -v grep)
		echo $daemon_name
		if ["$daemon_name" == ""]
		then
				cd ../CacheServer
				Debug/CacheServer &
		fi
	sleep 60
	done
fi

if [ 3 == $1 ]
then
	while [ 1 ]
	do
		daemon_name=$(ps -ef | grep LocationServer | grep -v grep)
		echo $daemon_name
		if ["$daemon_name" == ""]
		then
				cd ../LocationServer
				Debug/LocationServer &
		fi
	sleep 60
	done
fi 

if [ 4 == $1 ]
then
	while [ 1 ]
	do
		daemon_name=$(ps -ef | grep FriendsServer | grep -v grep)
		echo $daemon_name
		if ["$daemon_name" == ""]
		then
				cd ../FriendsServer
				Debug/FriendsServer &
		fi
	sleep 60
	done
fi 

if [ 5 == $1 ]
then
	while [ 1 ]
	do
		daemon_name=$(ps -ef | grep pz_channel2 | grep -v grep)
		echo $daemon_name
		if ["$daemon_name" == ""]
		then
				cd ../pz_channel
				Debug/pz_channel2 &
		fi
	sleep 60
	done
fi 

if [ 6 == $1 ]
then
	while [ 1 ]
	do
		daemon_name=$(ps -ef | grep GuildServer | grep -v grep)
		echo $daemon_name
		if ["$daemon_name" == ""]
		then
				cd ../GuildServer
				Debug/GuildServer &
		fi
	sleep 60
	done
fi 
